﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Util
{
    public static class JobRequest
    {
        public static HttpRequest Request
        {
            get
            {
                return HttpContext.Current.Request;
            }
        }
        public static HttpResponse Response
        {
            get
            {
                return HttpContext.Current.Response;
            }
        }

        public static string GetRequestString(string key)
        {
            if (!string.IsNullOrEmpty(Request[key]))
            {
                string result = HttpContext.Current.Server.UrlDecode(Request[key]).Trim().Replace("选择审核意见","").Replace("选择审批意见", "");
                return result;
            }
            else
            {
                return "";
            }
        }
        public static string GetRequestString(string key, string defaultVal)
        {
            if (string.IsNullOrEmpty(Request[key]))
            {
                return defaultVal;
            }
            else
            {
                return Request[key];
            }
        }
        public static int GetRequestInt(string key)
        {
            return GetRequestInt(key, 0);
        }
        public static int GetRequestInt(string key, int defaultVal)
        {
            int result;
            if (!int.TryParse(Request[key], out result))
            {
                result = defaultVal;
            }
            return result;
        }
        public static bool GetRequestBool(string key)
        {
            return GetRequestBool(key, false);
        }
        public static bool GetRequestBool(string key, bool defaultVal)
        {
            bool result;
            if (!bool.TryParse(Request[key], out result))
            {
                result = defaultVal;
            }
            return result;
        }
        public static double GetRequestDouble(string key)
        {
            return GetRequestDouble(key, 0.00);
        }
        public static double GetRequestDouble(string key, double defaultVal)
        {
            double result;
            if (!double.TryParse(Request[key], out result))
            {
                result = defaultVal;
            }
            return result;
        }
        public static decimal GetRequestDecimal(string key)
        {
            decimal result;
            if (!decimal.TryParse(Request[key], out result))
            {
                result = 0;
            }
            return result;
        }
        public static float GetRequestFloat(string key)
        {
            float result;
            if (!float.TryParse(Request[key], out result))
            {
                result = 0;
            }
            return result;
        }
        public static DateTime GetRequestDateTime(string key)
        {
            DateTime result;
            if (!DateTime.TryParse(Request[key], out result))
            {
                result = DateHelper.DefaultDate;
            }
            return result;
        }
        
    }
}
